package com.quartz.config;

import org.quartz.spi.TriggerFiredBundle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.scheduling.quartz.AdaptableJobFactory;
import org.springframework.stereotype.Component;

/**
 * @描述: 自动注入管理job(解决job无法被spring容器注入问题)
 * @类名:
 * @作者: yangshuang
 * @创建时间: 2017/8/18 9:00
 * @版本: v1.0
 */
@Component
public class SpringBeanJobFactory extends AdaptableJobFactory{

    @Autowired
    private AutowireCapableBeanFactory capableBeanFactory;
    @Override
    protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {

        //调用父类
        Object jobInstance=super.createJobInstance(bundle);
        //注入
        capableBeanFactory.autowireBean(jobInstance);
        return jobInstance;
    }
}
